package com.lg.service.impl;

import java.sql.SQLException;
import java.util.List;

import com.lg.dao.Example;
import com.lg.dao.criteria.AngelCommentCriteria;
import com.lg.model.AngelComment;
import com.lg.serivce.AngelCommentService;
import com.lg.util.PageUtilBean;

public class AngelCommentServiceImpl extends GenericServiceImpl<AngelComment>
		implements AngelCommentService {
	/**
	 * 查询选手的评论
	 * @param currentPage
	 * @param promoterId
	 * @return
	 */
	public PageUtilBean findAngelComments(String currentPage,String promoterId){
		Example<AngelCommentCriteria> e = new Example<AngelCommentCriteria>(AngelCommentCriteria.class);
		AngelCommentCriteria c = e.createCriteria();
		c.andPromoterIdEqualTo(promoterId);
		
		int count = countAngelComments(e); 
		
		PageUtilBean pageUtilBean = new PageUtilBean();
		pageUtilBean.setOnePageCount("10");
		pageUtilBean.setResultCount(count);
		pageUtilBean.setCurrentPage(currentPage); 
		int n = pageUtilBean.getStart();
		
		try {
			List list = this.getBaseDAO().getAngelCommentDAO().selectListByStatementId("angelComments", promoterId, n, pageUtilBean.getOnePageCount());
			if(list!=null){
				pageUtilBean.setModelList(list);
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		return pageUtilBean;
	}
	
	private int countAngelComments(Example e){
		int n = 0;
		try {
			n = this.getBaseDAO().getAngelCommentDAO().countByExample(e);
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		return n;
	}
}
